package com.zjj.edu.system.service.impl;

import com.zjj.edu.common.constant.UserConstants;
import com.zjj.edu.common.utils.StringUtils;
import com.zjj.edu.system.domain.SysStudent;
import com.zjj.edu.system.mapper.SysStudentMapper;
import com.zjj.edu.system.service.ISysStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 * @author zjj
 * @date 2020-09-05
 */
@Service
public class SysStudentServiceImpl implements ISysStudentService
{
    @Autowired
    private SysStudentMapper sysStudentMapper;

    @Override
    public SysStudent selectSysStudentById(Long id, Long tenantId) {
        return sysStudentMapper.selectSysStudentById(id, tenantId);
    }

    @Override
    public List<SysStudent> selectSysStudentList(SysStudent student) {
        return sysStudentMapper.selectSysStudentList(student);
    }

    @Override
    public int insertSysStudent(SysStudent student) {
        return sysStudentMapper.insertSysStudent(student);
    }

    @Override
    public int updateSysStudent(SysStudent student) {
        return sysStudentMapper.updateSysStudent(student);
    }

    @Override
    public String checkNameUnique(SysStudent vo) {
        Long id = StringUtils.isNull(vo.getId()) ? -1L : vo.getId();
        SysStudent info = sysStudentMapper.checkNameUnique(vo.getName(), vo.getTenantId());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue())
        {
            return UserConstants.NAME_NOT_UNIQUE;
        }
        return UserConstants.NAME_UNIQUE;
    }
}
